<?php
// +----------------------------------------------------------------------
// | SwiftPHP [ JUST DO ONE THING WELL ]
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2017  http://swiftphp.zhongwenyu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: zhongwenyu <zhongwenyu1987@163.com> <http://www.zhongwenyu.com>
// +----------------------------------------------------------------------
// | Times: 2017/2/22 19:34
// +----------------------------------------------------------------------
namespace swift;

class Controller{
    use \traits\Jump;

    // request实例
    protected $request = null;
    // view实例
    protected $view = null;

    /**
     * 架构函数
     * @param Request $request Request对象
     * @access public
     */
    public function __construct(Request $request = null){
        if(is_null($request)){
            $request = Request::instance();
        }

        $this->request = $request;
    }

    /**
     * 视图初始化
     * @return object $this
     */
    protected function view(){
        if(is_null($this->view)){
            $this->view = View::instance(Config::get('template') , Config::get('view_replace_str'));
        }
        return $this->view;
    }


    protected function __initialize(){}

    /**
     * 模板变量赋值
     * @access protected
     * @param mixed $name  要显示的模板变量
     * @param mixed $value 变量的值
     * @return void
     */
    public function assign($name, $value = '')
    {
        $this->view()->assign($name, $value);
    }

    /**
     * 加载模板输出
     * @access protected
     * @param string $template 模板文件名
     * @param array  $vars     模板输出变量
     * @return mixed
     */
    public function fetch($tpl = '' , $vars = []){
        return $this->view()->fetch($tpl , $vars);
    }
}